package com.dmgis.qxfw.dataservice.businessservice.nyfw.controller;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByUpdate;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.ny.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.users;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ResultObj;
import com.dmgis.qxfw.dataservice.businessservice.common.util.FileUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.JsonUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.StringUtil;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.nyfw.service.FarmXxHdService;
import com.dmgis.qxfw.dataservice.commonservice.utils.DateTime;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @ClassName FarmXxHdController
 * @Description TODO 信息互动模块-协管员上报信息管理、值班日志、信息员管理、协管员管理、信息录入
 * @Author sun
 * @Date 2021/7/27 13:15
 * @Version 1.0
 **/
@Controller
@RequestMapping("/nyfw")
public class FarmXxHdController {

    @Resource
    private FarmXxHdService farmXxHdService;

    MongoService1 ms = new MongoService1();

    ProcessRequestController pc = new ProcessRequestController();
    private  final String operatingSystem;

    @Autowired
    public FarmXxHdController(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }
    /**
     * 修改密码
     */
    @RequestMapping("/updatePassWord")
    @ResponseBody
    public Object updatePassWord(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                String password = jsonObject.getString("password");
                Map<String, String> selectParam = new HashMap<String, String>();
                String message = "";
                //农业大户 农业局
                    if ("1".equals(user.getType()) ||"4".equals(user.getType())) {
                        RequestDataByUpdate<String, users> dataByDelete = new RequestDataByUpdate<String, users>();
                        List<users> usersList = farmXxHdService.getUser(user.getUsername());
                        dataByDelete.setParam("id = '" + usersList.get(0).getId() + "'");
                        users user1 = new users();
                        user1.setPassword(password);
                        dataByDelete.setData(user1);
                        selectParam.put("method", "users");
                        selectParam.put("sqlType", "update");
                        selectParam.put("advCode", DbConfig.advCode);
                        selectParam.put("param", JsonUtil.object2Json(dataByDelete));
                        message = pc.processRequest(selectParam);
                }
                //协理员
                if ("3".equals(user.getType())) {
                    RequestDataByUpdate<String, Coordinator> dataByDelete = new RequestDataByUpdate<String, Coordinator>();
                    List<Coordinator> crossingGuard = farmXxHdService.getCrossingGuard(user.getUsername());
                    dataByDelete.setParam("id='" + crossingGuard.get(0).getId() + "'");
                    Coordinator coordinator = new Coordinator();
                    coordinator.setCoordinatepwd(password);
                    dataByDelete.setData(coordinator);
                    selectParam.put("method", "coordinator");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("sqlType", "update");
                    selectParam.put("param", JsonUtil.object2Json(dataByDelete));
                    message = pc.processRequest(selectParam);
                }
                //信息员
                if ("2".equals(user.getType())) {
                    RequestDataByUpdate<String, Infocollector> dataByDelete = new RequestDataByUpdate<String, Infocollector>();
                    List<Infocollector> infor = farmXxHdService.getInfor(user.getUsername());
                    Infocollector infocollector = new Infocollector();
                    infocollector.setInfocollectorpwd(password);
                    dataByDelete.setData(infocollector);
                    dataByDelete.setParam("id='" + infor.get(0).getId() + "'");
                    selectParam.put("method", "infocollector");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("sqlType", "update");
                    selectParam.put("param", JsonUtil.object2Json(dataByDelete));
                    message = pc.processRequest(selectParam);
                }
                if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                    return new ResultObj("密码修改成功!", message, true);
                }
            }
        } catch (Exception e) {
            return new ResultObj("密码修改失败!", e.getMessage(), false);
        }
        return new ResultObj("密码修改失败!", "params解析失败", false);
    }

    /**
     * @Description: 查询所有协管员
     * @Author: sunshine
     * @Date: 2021/7/27 13:22
     **/
    @RequestMapping("/bindCoordinateName")
    @ResponseBody
    public Object bindCoordinateName(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.bindCoordinateName();
        return agrisrvList;
    }

    /**
     * @Description: 协管员上报信息管理-上报信息查看
     * @Author: sunshine
     * @Date: 2021/7/27 13:19
     **/
    @RequestMapping("/getCrossingGuardView")
    @ResponseBody
    public Object getCrossingGuardView(HttpServletRequest request) {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String name = request.getParameter("name");
        List<CoordinatorInfo> agrisrvList = farmXxHdService.getCrossingGuardView(startDate, endDate, name);
        if (agrisrvList != null) {
            for (CoordinatorInfo coordinatorInfo : agrisrvList) {
                //图片查询
                String serviceFilePath = "";
                // 下载
                String imgurl = coordinatorInfo.getImgpath();
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/CrossingGuard/";
                String serviceUrl = basePath + imgurl;
                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\CrossingGuard\\";
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/CrossingGuard/";
                }

                serviceFilePath = urlpath + imgurl;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                // 如果目录中不存在文件，下载雷达文件到temp目录
                File serviceFile = new File(serviceFilePath);// 服务器文件
                if (!serviceFile.exists()) {// 把文件上传到服务器
                    Map<String, Object> queryMap = new HashMap<String, Object>();
                    queryMap.put("id", coordinatorInfo.getId());
                    queryMap.put("table_name", "coordinator_info");
                    String imgpath = coordinatorInfo.getImgpath();
                    String type = imgpath.split("[.]")[imgpath.split("[.]").length - 1];
                    if (type.contains("doc"))
                        queryMap.put("collectionName", "doc_file");
                    else if (type.contains("pdf"))
                        queryMap.put("collectionName", "pdf_file");
                    else
                        queryMap.put("collectionName", "image_file");
                    queryMap.put("advCode", DbConfig.advCode);
                    byte[] data = ms.selectData(queryMap);
                    if (data == null) {
                        serviceFilePath = "";
                    } else {
                        FileUtil.bytesToFile(data, serviceFilePath);
                    }
                }
                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String imagepath = serviceFilePath;
                //添加视频路径
                coordinatorInfo.setImgpath(imagepath);
            }
        }
        return agrisrvList;
    }

    /**
     * @Description: 协管员上报信息管理-删除上报信息
     * @Author: sunshine
     * @Date: 2021/7/27 14:38
     **/
    @RequestMapping("/deleteCrossingGuardInfo")
    @ResponseBody
    public Object deleteCrossingGuardInfo(HttpServletRequest request) {
        String id = request.getParameter("id");
        if (StringUtil.IsNullOrEmpty(id))
            return new ResultObj("查询失败!", "id不能为空!", false);
        Object agrisrvList = farmXxHdService.deleteCrossingGuard(id);
        return agrisrvList;
    }

    /**
     * @Description: 协管员上报信息
     * @Author: sunshine
     * @Date: 2021/7/28 14:34
     **/
    @RequestMapping(value = "/AddCrossingGuard", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object AddCrossingGuard(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws ParseException {
        String message = request.getParameter("message");
        String userName = request.getParameter("userName");
        String startDate = request.getParameter("startDate");
        DateTime time = DateTime.now();
        String timetemp = time.toDateTimeString("yyyyMMddHHmmss");
        String name = timetemp + "XGY" + userName + file.getOriginalFilename();
        CoordinatorInfo info = new CoordinatorInfo();
        info.setCoordinatename(userName);
        info.setDatereport(DateTime.parseDateTime(startDate).toDate());
        info.setImgpath(name);
        info.setMessagereport(message);
        Object result = farmXxHdService.AddCrossingGuard(info, file, request);
        return result;
    }

    /**
     * @Description: 协理员上报回复-根据ID查看详细信息
     * @Author: sunshine
     * @Date: 2021/7/28 15:30
     **/
    @RequestMapping("/getCrossingGuardByID")
    @ResponseBody
    public Object getCrossingGuardByID(HttpServletRequest request) {
        String ID = request.getParameter("id");
        if (StringUtil.IsNullOrEmpty(ID))
            return new ResultObj("查询失败!", "id不能为空!", false);
        Object agrisrvList = farmXxHdService.getCrossingGuardByID(ID);
        return agrisrvList;
    }

    /**
     * @Description: 协理员上报回复-回复消息（更新操作）
     * @Author: sunshine
     * @Date: 2021/7/28 15:32
     **/
    @RequestMapping("/rervertCrossingGuard")
    @ResponseBody
    public Object rervertCrossingGuard(HttpServletRequest request) {
        String ID = request.getParameter("id");
        if (StringUtil.IsNullOrEmpty(ID))
            return new ResultObj("操作失败!", "id不能为空!", false);
        String message = request.getParameter("message");
        String userName = request.getParameter("userName");
        DateTime time = DateTime.now();
        CoordinatorInfo info = new CoordinatorInfo();
        info.setNamereply(userName);
        info.setDatereply(Timestamp.valueOf(time.toDateTimeString("yyyy-MM-dd HH:mm:ss")));
        info.setMessagereply(message);
        info.setId(ID);
        Object agrisrvList = farmXxHdService.rervertCrossingGuard(info);
        return agrisrvList;
    }



    /**
     * @Description: 值班日志添加
     * @Author: sunshine
     * @Date: 2021/7/28 15:43
     **/
    @RequestMapping("/insertDutylog")
    @ResponseBody
    public Object insertDutylog(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                Dutylog zbry = jsonObject.getObject("dutlog", Dutylog.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "dutylog传递有误!", false);
                Object result = farmXxHdService.insertDutylog(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志自动填充 姓名,单位
     * 得到最新的城镇预报时间、时次
     * 查询对应时间时次的城镇预报信息
     * @Author: sunshine
     * @Date: 2021/7/29 10:19
     **/
    @RequestMapping("/getInfocollectorbyName")
    @ResponseBody
    public Object getInfocollectorbyName(HttpServletRequest request) {
        String username = request.getParameter("username");
        Object agrisrvList = farmXxHdService.getInfocollectorbyName(username);
        return agrisrvList;
    }

    /**
     * @Description: 值班日志查询历史记录
     * @Author: sunshine
     * @Date: 2021/7/29 10:57
     **/
    @RequestMapping("/getDutylog")
    @ResponseBody
    public Object getDutylog(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String startDate = jsonObject.getString("startDate");
                String endDate = jsonObject.getString("endDate");
                String id = jsonObject.getString("id");
                Object agrisrvList = farmXxHdService.getDutylog(zbry, startDate, endDate, id);
                return agrisrvList;
            }
            return new ResultObj("查询失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志删除
     * @Author: sunshine
     * @Date: 2021/7/29 11:12
     **/
    @RequestMapping("/deleteDutylog")
    @ResponseBody
    public Object deleteDutylog(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String startDate = jsonObject.getString("startDate");
                String endDate = jsonObject.getString("endDate");
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteDutylog(zbry, startDate, endDate, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志更新
     * @Author: sunshine
     * @Date: 2021/7/29 11:12
     **/
    @RequestMapping("/updateDutylog")
    @ResponseBody
    public Object updateDutylog(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                Dutylog dutylog= jsonObject.getObject("dutylog", Dutylog.class);
                String startDate = jsonObject.getString("startDate");
                String endDate = jsonObject.getString("endDate");
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "user传递有误!", false);
                if (dutylog == null)
                    return new ResultObj("更新失败!", "dutylog传递有误!", false);
                Object agrisrvList = farmXxHdService.updateDutylog(dutylog, zbry, startDate, endDate, id);
                return agrisrvList;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 添加信息员
     * @Author: sunshine
     * @Date: 2021/7/28 15:43
     **/
    @RequestMapping("/insertInfor")
    @ResponseBody
    public Object insertInfor(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                Infocollector zbry= jsonObject.getObject("Infor", Infocollector.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "Infor传递有误!", false);
                Object result = farmXxHdService.insertInfor(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据用户账号查询信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:15
     **/
    @RequestMapping("/getInfor")
    @ResponseBody
    public Object getInfor(HttpServletRequest request) {
        String username = request.getParameter("username");
        List<Infocollector> infor = farmXxHdService.getInfor(username);
        if (infor != null && infor.size() > 0) {
            return new ResultObj("查询成功!", infor, true);
        }
        return new ResultObj("查询失败!", "", false);
    }

    /**
     * @Description: 删除信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:16
     **/
    @RequestMapping("/deleteInfor")
    @ResponseBody
    public Object deleteInfor(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteInfor(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 更新信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:16
     **/
    @RequestMapping("/updateInfor")
    @ResponseBody
    public Object updateInfor(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                Infocollector Infor = jsonObject.getObject("Infor", Infocollector.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (user == null)
                    return new ResultObj("更新失败!", "user传递有误!", false);
                if (Infor == null)
                    return new ResultObj("更新失败!", "Infor传递有误!", false);
                Object agrisrvList = farmXxHdService.updateInfor(Infor, user, id);
                return agrisrvList;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }


    /**
     * @Description: 添加协管员
     * @Author: sunshine
     * @Date: 2021/7/28 15:43
     **/
    @RequestMapping("/insertCrossingGuard")
    @ResponseBody
    public Object insertCrossingGuard(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                Coordinator zbry = jsonObject.getObject("coordinator", Coordinator.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "coordinator传递有误!", false);
                Object result = farmXxHdService.insertCrossingGuard(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据用户账号查询协管员
     * @Author: sunshine
     * @Date: 2021/7/29 14:15
     **/
    @RequestMapping("/getCrossingGuard")
    @ResponseBody
    public Object getCrossingGuard(HttpServletRequest request) {
        String CoordinateName = request.getParameter("CoordinateName");
        List<Coordinator> crossingGuard = farmXxHdService.getCrossingGuard(CoordinateName);
        if(crossingGuard != null && crossingGuard.size() > 0) {
            return new ResultObj("查询成功!", crossingGuard, true);
        }
        return new ResultObj("查询失败!", "", false);
    }

    /**
     * @Description: 删除协管员
     * @Author: sunshine
     * @Date: 2021/7/29 14:16
     **/
    @RequestMapping("/deleteCrossingGuard")
    @ResponseBody
    public Object deleteCrossingGuard(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteCrossingGuard(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 更新协管员
     * @Author: sunshine
     * @Date: 2021/7/29 14:58
     **/
    @RequestMapping("/updateCrossingGuard")
    @ResponseBody
    public Object updateCrossingGuard(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                Coordinator Infor = jsonObject.getObject("coordinator", Coordinator.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (user == null)
                    return new ResultObj("更新失败!", "user传递有误!", false);
                if (Infor == null)
                    return new ResultObj("更新失败!", "coordinator传递有误!", false);
                Object agrisrvList = farmXxHdService.updateCrossingGuard(Infor, user, id);
                return agrisrvList;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据站点名称查询作展示 - 农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 14:57
     **/
    @RequestMapping("/getNFStaInfo")
    @ResponseBody
    public Object getNFStaInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getNFStaInfo(staName, request);
        return agrisrvList;
    }

    /**
     * @Description: 获取农作物
     * @Author: sunshine
     * @Date: 2021/7/29 15:13
     **/
    @RequestMapping("/getCrops")
    @ResponseBody
    public Object getCrops(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getCrops();
        return agrisrvList;
    }

    /**
     * @Description: 新增农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 15:23
     **/
    @RequestMapping("/addNFStaNotFile")
    @ResponseBody
    public Object addNFStaNotFile(@RequestParam("params") String params , HttpServletRequest request) {
        if (params != null) {
            JSONObject jsonObject = JSONObject.parseObject(params);
            StationInfo zbry = jsonObject.getObject("StationInfo", StationInfo.class);
            String userName = jsonObject.getString("userName");
            String userType = jsonObject.getString("userType");
            if (zbry == null)
                return new ResultObj("新增失败!", "StationInfo传递有误!", false);
            StationInfo stationInfo = farmXxHdService.addNFSta(zbry, userType, userName);
            if (stationInfo != null) {
                return new ResultObj("新增成功!", "", true);
            }
        }
        return new ResultObj("新增失败！", "params参数错误", false);
    }
    /**
     * @Description: 新增农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 15:23
     **/
    @RequestMapping("/addNFSta")
    @ResponseBody
    public Object addNFSta(@RequestParam("params") String params,@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                StationInfo zbry = jsonObject.getObject("StationInfo", StationInfo.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (zbry == null)
                    return new ResultObj("新增失败!", "StationInfo传递有误!", false);
                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\StationPic\\";
                }else {
                   urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/StationPic/";
                }

                FileUtil.mkDirs(urlpath);
                FileUtil.ClearTempFiles(urlpath, 100);
                String fileName = file.getOriginalFilename();// 文件名
                String fName = DateTime.now().toDateString() + fileName;
                zbry.setPic(fName);
                String localPath = urlpath + fName;
                File localFile = new File(localPath);
                int returnTag = -1;
                if (localFile.exists()) {
                    returnTag = -1;
                }
                //新增数据库
                StationInfo stationInfo = farmXxHdService.addNFSta(zbry, userType, userName);
                if (stationInfo != null && file!=null) {
                    byte[] bytes = file.getBytes();
                    String bytesString = new String(bytes, "ISO-8859-1");
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("stationid", stationInfo.getStationid());
                    map.put("table_name", "station_info");
                    map.put("collectionName", "image_file");
                    map.put("advCode", DbConfig.advCode);
                    map.put("data", bytesString.getBytes("ISO-8859-1"));
                    returnTag = ms.insertData(map);
                    file.transferTo(localFile);
                    if (returnTag != -1) {
                        return new ResultObj("新增成功", returnTag, true);
                    }
                }
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }



    /**
     * @Description: 更新农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 15:23
     **/
    @RequestMapping("/updateNFSta")
    @ResponseBody
    public Object updateNFSta(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                StationInfo zbry = jsonObject.getObject("StationInfo", StationInfo.class);
                String stationid = jsonObject.getString("stationid");
                if (zbry == null)
                    return new ResultObj("更新失败!", "StationInfo传递有误!", false);
                int result = (int)farmXxHdService.updateNFSta(user, zbry,stationid);
                if (result > 0) {
                    return new ResultObj("更新成功!", result, true);
                }
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }
    /**
     * @Description: 更新农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 15:23
     **/
    @RequestMapping("/updateNFStaPic")
    @ResponseBody
    public Object updateNFStaPic(@RequestParam("params") String params, @RequestParam("file") MultipartFile file,HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                StationInfo zbry = jsonObject.getObject("StationInfo", StationInfo.class);
                String stationid = jsonObject.getString("stationid");
                if (zbry == null)
                    return new ResultObj("修改失败!", "StationInfo传递有误!", false);
                String urlpath ;
                if (operatingSystem.equals("Windows")){
                    urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\StationPic\\";
                }else {
                    urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/StationPic/";
                }

                FileUtil.mkDirs(urlpath);
                FileUtil.ClearTempFiles(urlpath, 100);
                String fileName = file.getOriginalFilename();// 文件名
                String fName = DateTime.now().toDateString() + fileName;
                zbry.setPic(fName);
                String localPath = urlpath + fileName;
                File localFile = new File(localPath);
                int returnTag = -1;
                if (localFile.exists()) {
                    returnTag = -1;
                }
                //修改数据库
                Object stationInfo = farmXxHdService.updateNFSta(user, zbry,stationid);
                if (stationInfo != null) {
                    byte[] bytes = file.getBytes();
                    String bytesString = new String(bytes, "ISO-8859-1");
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("stationid", zbry.getStationid());
                    map.put("table_name", "station_info");
                    map.put("collectionName", "image_file");
                    map.put("advCode", DbConfig.advCode);
                    Map<String, Object> mapdata = new HashMap<String, Object>();
                    mapdata.put("data", bytesString.getBytes("ISO-8859-1"));
                    returnTag = (int) ms.updateData(map, mapdata);
                    file.transferTo(localFile);
                    if (returnTag != -1) {
                        return new ResultObj("修改成功", returnTag, true);
                    }
                }
            }
        } catch (Exception ex) {
            return new ResultObj("修改失败!", ex.getMessage(), false);
        }
        return new ResultObj("修改失败", "", false);
    }

    /**
     * @Description: 删除农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 16:44
     **/
    @RequestMapping("/deleteNFStaInfo")
    @ResponseBody
    public Object deleteNFStaInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String stationid = jsonObject.getString("stationid");
                if (StringUtil.IsNullOrEmpty(stationid))
                    return new ResultObj("删除失败!", "stationid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                int agrisrvList = (int)farmXxHdService.deleteNFStaInfo(zbry, stationid);
                //删除成功
                if (agrisrvList > 0) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("stationid", stationid);
                    map.put("table_name", "station_info");
                    map.put("collectionName", "image_file");
                    map.put("advCode", DbConfig.advCode);
                    int returnTag = (int) ms.deleteData(map);
                    if (returnTag != -1) {
                        return new ResultObj("删除成功", returnTag, true);
                    }
                }
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return new ResultObj("删除失败!", "params不能正确解析", false);
    }

    /**
     * @Description: 根据作物品种做展示 - 发育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:04
     **/
    @RequestMapping("/getMatuIndex")
    @ResponseBody
    public Object getMatuIndex(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getMatuIndex(staName, request);
        return agrisrvList;
    }

    /**
     * @Description: 得到作物类别和名称
     * @Author: sunshine
     * @Date: 2021/7/29 15:13
     **/
    @RequestMapping("/getCropTypeAndName")
    @ResponseBody
    public Object getCropTypeAndName(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getCropTypeAndName();
        return agrisrvList;
    }

    /**
     * @Description: 得到发育期和作物名称
     * @Author: sunshine
     * @Date: 2021/7/29 15:13
     **/
    @RequestMapping("/getCropGrowdateAndName")
    @ResponseBody
    public Object getCropGrowdateAndName(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getCropGrowdateAndName();
        return agrisrvList;
    }

    /**
     * @Description: 新增生育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:09
     **/
    @RequestMapping("/addMatuIndex")
    @ResponseBody
    public Object addMatuIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                CropGrowdateIndexlib zbry = jsonObject.getObject("MatuIndex", CropGrowdateIndexlib.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "MatuIndex传递有误!", false);
                Object result = farmXxHdService.addMatuIndex(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据indexid修改发育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:24
     **/
    @RequestMapping("/updateMatuIndex")
    @ResponseBody
    public Object updateMatuIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                CropGrowdateIndexlib zbry = jsonObject.getObject("MatuIndex", CropGrowdateIndexlib.class);
                if (StringUtil.IsNullOrEmpty(zbry.getIndexid()))
                    return new ResultObj("更新失败!", "indexid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "MatuIndex传递有误!", false);
                Object result = farmXxHdService.updateMatuIndex(user, zbry);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据indexid删除发育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:27
     **/
    @RequestMapping("/deleteMatuIndex")
    @ResponseBody
    public Object deleteMatuIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String indexid = jsonObject.getString("indexid");
                if (StringUtil.IsNullOrEmpty(indexid))
                    return new ResultObj("删除失败!", "indexid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteMatuIndex(zbry, indexid);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物品种做展示 - 病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:32
     **/
    @RequestMapping("/getDisIndex")
    @ResponseBody
    public Object getDisIndex(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getDisIndex(staName);
        return agrisrvList;
    }

    /**
     * @Description: 新增病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:34
     **/
    @RequestMapping("/addDisIndex")
    @ResponseBody
    public Object addDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                Diseaseindexlib zbry = jsonObject.getObject("DisIndex", Diseaseindexlib.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "DisIndex传递有误!", false);
                Object result = farmXxHdService.addDisIndex(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改updateDisIndex  病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:42
     **/
    @RequestMapping("/updateDisIndex")
    @ResponseBody
    public Object updateDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                Diseaseindexlib zbry = jsonObject.getObject("DisIndex", Diseaseindexlib.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "DisIndex传递有误!", false);
                Object result = farmXxHdService.updateDisIndex(user, zbry, id);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除deleteDisIndex  病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:44
     **/
    @RequestMapping("/deleteDisIndex")
    @ResponseBody
    public Object deleteDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteDisIndex(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示  气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:47
     **/
    @RequestMapping("/getMeteoroDisIndex")
    @ResponseBody
    public Object getMeteoroDisIndex(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getMeteoroDisIndex(staName);
        return agrisrvList;
    }

    /**
     * @Description: 得到农作物易发灾害类型和名称
     * @Author: sunshine
     * @Date: 2021/7/30 10:49
     **/
    @RequestMapping("/getEasyhappentypeAndName")
    @ResponseBody
    public Object getEasyhappentypeAndName(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getEasyhappentypeAndName();
        return agrisrvList;
    }

    /**
     * @Description: 新增气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:52
     **/
    @RequestMapping("/addMeteoDisIndex")
    @ResponseBody
    public Object addMeteoDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                CropWeatherDistIndexlib zbry = jsonObject.getObject("MeteoDisIndex", CropWeatherDistIndexlib.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "MeteoDisIndex传递有误!", false);
                Object result = farmXxHdService.addMeteoDisIndex(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:55
     **/
    @RequestMapping("/updateMeteoDisIndex")
    @ResponseBody
    public Object updateMeteoDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                CropWeatherDistIndexlib zbry = jsonObject.getObject("MeteoDisIndex", CropWeatherDistIndexlib.class);
                if (StringUtil.IsNullOrEmpty(zbry.getId()))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "MeteoDisIndex传递有误!", false);
                Object result = farmXxHdService.updateMeteoDisIndex(user, zbry);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:57
     **/
    @RequestMapping("/deleteMeteoDisIndex")
    @ResponseBody
    public Object deleteMeteoDisIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteMeteoDisIndex(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示 历史发育期资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:00
     **/
    @RequestMapping("/getHistoryMatuInfo")
    @ResponseBody
    public Object getHistoryMatuInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getHistoryMatuInfo(staName);
        return agrisrvList;
    }

    /**
     * @Description: 新增历史发育期资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:02
     **/
    @RequestMapping("/addHistoryMatuInfo")
    @ResponseBody
    public Object addHistoryMatuInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                CropGrowdateHistory zbry = jsonObject.getObject("HistoryMatuInfo", CropGrowdateHistory.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "HistoryMatuInfo传递有误!", false);
                Object result = farmXxHdService.addHistoryMatuInfo(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改历史发育期资料updateHistoryMatuInfo
     * @Author: sunshine
     * @Date: 2021/7/30 11:04
     **/
    @RequestMapping("/updateHistoryMatuInfo")
    @ResponseBody
    public Object updateHistoryMatuInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                CropGrowdateHistory zbry = jsonObject.getObject("HistoryMatuInfo", CropGrowdateHistory.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "HistoryMatuInfo传递有误!", false);
                Object result = farmXxHdService.updateHistoryMatuInfo(user, zbry, id);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除历史发育期资料deleteHistoryMatuInfo
     * @Author: sunshine
     * @Date: 2021/7/30 11:06
     **/
    @RequestMapping("/deleteHistoryMatuInfo")
    @ResponseBody
    public Object deleteHistoryMatuInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteHistoryMatuInfo(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:09
     **/
    @RequestMapping("/getHistoryYieldsInfo")
    @ResponseBody
    public Object getHistoryYieldsInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getHistoryYieldsInfo(staName);
        return agrisrvList;
    }

    /**
     * @Description: 新增历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:23
     **/
    @RequestMapping("/addHistoryYieldsInfo")
    @ResponseBody
    public Object addHistoryYieldsInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                CropyieldHistory zbry = jsonObject.getObject("HistoryYieldsInfo", CropyieldHistory.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "HistoryYieldsInfo传递有误!", false);
                Object result = farmXxHdService.addHistoryYieldsInfo(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:25
     **/
    @RequestMapping("/updateHistoryYieldsInfo")
    @ResponseBody
    public Object updateHistoryYieldsInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                CropyieldHistory zbry = jsonObject.getObject("HistoryYieldsInfo", CropyieldHistory.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "HistoryYieldsInfo传递有误!", false);
                Object result = farmXxHdService.updateHistoryYieldsInfo(user, zbry, id);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:28
     **/
    @RequestMapping("/deleteHistoryYieldsInfo")
    @ResponseBody
    public Object deleteHistoryYieldsInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteHistoryYieldsInfo(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:49
     **/
    @RequestMapping("/getHistoryDisInfo")
    @ResponseBody
    public Object getHistoryDisInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getHistoryDisInfo(staName);
        return agrisrvList;
    }

    /**
     * @Description: 得到病虫害名称和作物名称
     * @Author: sunshine
     * @Date: 2021/7/30 12:54
     **/
    @RequestMapping("/getDiseasesnameAndName")
    @ResponseBody
    public Object getDiseasesnameAndName(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getDiseasesnameAndName();
        return agrisrvList;
    }

    /**
     * @Description: 获取站点信息
     * @Author: sunshine
     * @Date: 2021/7/30 13:00
     **/
    @RequestMapping("/getNfStationID")
    @ResponseBody
    public Object getNfStationID(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getNfStationID();
        return agrisrvList;
    }

    /**
     * @Description: 新增历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:07
     **/
    @RequestMapping("/addHistoryDisInfo")
    @ResponseBody
    public Object addHistoryDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                Diseasedatalib zbry = jsonObject.getObject("HistoryDisInfo", Diseasedatalib.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "HistoryDisInfo传递有误!", false);
                Object result = farmXxHdService.addHistoryDisInfo(zbry, userType, userName);
                if ("1".equals(result)) {
                    return new ResultObj("新增成功!", result, true);
                }
                return new ResultObj("新增失败!", result, false);
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据stationid修改历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:09
     **/
    @RequestMapping("/updateHistoryDisInfo")
    @ResponseBody
    public Object updateHistoryDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                Diseasedatalib zbry = jsonObject.getObject("HistoryDisInfo", Diseasedatalib.class);
                String stationid = jsonObject.getString("stationid");
                if (StringUtil.IsNullOrEmpty(stationid))
                    return new ResultObj("更新失败!", "stationid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "HistoryDisInfo传递有误!", false);
                //pg集群修改主键 先删除 在新增
                Object deletehistory = farmXxHdService.deleteHistoryDisInfo(user, stationid);
                if ("1".equals(deletehistory)) {
                    Object addhistory = farmXxHdService.addHistoryDisInfo(zbry, user.getType(), user.getUsername());
                    if ("1".equals(addhistory)) {
                        return new ResultObj("更新成功!", addhistory, true);
                    }
                    return new ResultObj("更新失败!", addhistory, false);
                }
                return new ResultObj("更新失败!", deletehistory, false);
            }
        } catch (Exception ex) {
            //TODO
        }
        return new ResultObj("更新失败!", "params不能正确解析", false);
    }

    /**
     * @Description: 根据stationid删除历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:12
     **/
    @RequestMapping("/deleteHistoryDisInfo")
    @ResponseBody
    public Object deleteHistoryDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String stationid = jsonObject.getString("stationid");
                if (StringUtil.IsNullOrEmpty(stationid))
                    return new ResultObj("删除失败!", "stationid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteHistoryDisInfo(zbry, stationid);
                if ("1".equals(agrisrvList)) {
                    return new ResultObj("删除成功!", agrisrvList, true);
                }
                return new ResultObj("删除失败!", agrisrvList, false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return new ResultObj("删除失败!", "params不能正确解析", false);
    }

    /**
     * @Description: 根据作物名做展示历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:17
     **/
    @RequestMapping("/getHistoryMeteoDisInfo")
    @ResponseBody
    public Object getHistoryMeteoDisInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getHistoryMeteoDisInfo(staName);
        return agrisrvList;
    }

    /**
     * @Description: 历史气象灾害资料 - 灾害种类
     * @Author: sunshine
     * @Date: 2021/7/30 13:19
     **/
    @RequestMapping("/getDisastertype")
    @ResponseBody
    public Object getDisastertype(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getDisastertype();
        return agrisrvList;
    }

    /**
     * @Description: 新增历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:25
     **/
    @RequestMapping("/addHistoryMeteoDisInfo")
    @ResponseBody
    public Object addHistoryMeteoDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                AgriWeatherDistRecord zbry = jsonObject.getObject("HistoryMeteoDisInfo", AgriWeatherDistRecord.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "HistoryMeteoDisInfo传递有误!", false);
                Object result = farmXxHdService.addHistoryMeteoDisInfo(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:28
     **/
    @RequestMapping("/updateHistoryMeteoDisInfo")
    @ResponseBody
    public Object updateHistoryMeteoDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                AgriWeatherDistRecord zbry = jsonObject.getObject("HistoryMeteoDisInfo", AgriWeatherDistRecord.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("更新失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "HistoryMeteoDisInfo传递有误!", false);
                Object result = farmXxHdService.updateHistoryMeteoDisInfo(user, zbry, id);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
    * @Description: 根据id删除历史气象灾害资料
    * @Author: sunshine
    * @Date: 2021/7/30 13:31
    **/
    @RequestMapping("/deleteHistoryMeteoDisInfo")
    @ResponseBody
    public Object deleteHistoryMeteoDisInfo(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteHistoryMeteoDisInfo(zbry, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
    * @Description: 根据作物名做展示农事活动指标
    * @Author: sunshine
    * @Date: 2021/7/30 13:34
    **/
    @RequestMapping("/getNSServiceIndexInfo")
    @ResponseBody
    public Object getNSServiceIndexInfo(HttpServletRequest request) {
        String staName = request.getParameter("staName");
        Object agrisrvList = farmXxHdService.getNSServiceIndexInfo(staName);
        return agrisrvList;
    }

    /**
    * @Description: 指数名称
    * @Author: sunshine
    * @Date: 2021/7/30 13:36
    **/
    @RequestMapping("/getIndexname")
    @ResponseBody
    public Object getIndexname(HttpServletRequest request) {
        Object agrisrvList = farmXxHdService.getIndexname();
        return agrisrvList;
    }

    /**
    * @Description: 新增农事活动指标
    * @Author: sunshine
    * @Date: 2021/7/30 13:38
    **/
    @RequestMapping("/addNSSrvIndex")
    @ResponseBody
    public Object addNSSrvIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                AgriServiceIndex zbry = jsonObject.getObject("NSSrvIndex", AgriServiceIndex.class);
                String userName = jsonObject.getString("userName");
                String userType = jsonObject.getString("userType");
                if (StringUtil.IsNullOrEmpty(userType))
                    return new ResultObj("新增失败!", "userType不能为空!", false);
                if (StringUtil.IsNullOrEmpty(userName))
                    return new ResultObj("新增失败!", "userName不能为空!", false);
                if (zbry == null)
                    return new ResultObj("新增失败!", "NSSrvIndex传递有误!", false);
                Object result = farmXxHdService.addNSSrvIndex(zbry, userType, userName);
                return result;
            }
            return new ResultObj("新增失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
    * @Description: 根据indexid修改农事活动指标
    * @Author: sunshine
    * @Date: 2021/7/30 13:40
    **/
    @RequestMapping("/updateNSSrvIndex")
    @ResponseBody
    public Object updateNSSrvIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                AgriServiceIndex zbry = jsonObject.getObject("NSSrvIndex", AgriServiceIndex.class);
                String indexid = jsonObject.getString("indexid");
                if (StringUtil.IsNullOrEmpty(indexid))
                    return new ResultObj("更新失败!", "indexid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("更新失败!", "NSSrvIndex传递有误!", false);
                Object result = farmXxHdService.updateNSSrvIndex(user, zbry, indexid);
                return result;
            }
            return new ResultObj("更新失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
    * @Description: 根据indexid删除农事活动指标
    * @Author: sunshine
    * @Date: 2021/7/30 13:42
    **/
    @RequestMapping("/deleteNSSrvIndex")
    @ResponseBody
    public Object deleteNSSrvIndex(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users zbry = jsonObject.getObject("user", users.class);
                String indexid = jsonObject.getString("indexid");
                if (StringUtil.IsNullOrEmpty(indexid))
                    return new ResultObj("删除失败!", "indexid不能为空!", false);
                if (zbry == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteNSSrvIndex(zbry, indexid);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    @RequestMapping("/rervertShangBao")
    @ResponseBody
    public Object rervertShangBao(HttpServletRequest request) {
        String ID = request.getParameter("id");
        String userName = request.getParameter("userName");
        String message = request.getParameter("message");
        if (StringUtil.IsNullOrEmpty(ID))
            return new ResultObj("操作失败!", "id不能为空!", false);
        InfocollectorInfo info = new InfocollectorInfo();
        info.setId(ID);
        info.setMessagereply(message);
        info.setNamereply(userName);
        info.setDatereply(DateTime.now().toDate());
        Object agrisrvList = farmXxHdService.rervertShangBao(info);
        return agrisrvList;
    }


    /**
     * 删除上报信息
     * @param params
     * @param request
     * @return
     */
    @RequestMapping("/deleteShangBaoById")
    @ResponseBody
    public Object deleteShangBaoById(@RequestParam("params") String params, HttpServletRequest request) {
        try {
            if (params != null) {
                JSONObject jsonObject = JSONObject.parseObject(params);
                users user = jsonObject.getObject("user", users.class);
                String id = jsonObject.getString("id");
                if (StringUtil.IsNullOrEmpty(id))
                    return new ResultObj("删除失败!", "id不能为空!", false);
                if (user == null)
                    return new ResultObj("删除失败!", "user传递有误!", false);
                Object agrisrvList = farmXxHdService.deleteShangBaoById(user, id);
                return agrisrvList;
            }
            return new ResultObj("删除失败!", "params不能正确解析", false);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }
}
